package com.faithnmn.learnenglishbc.adapter;

import java.util.ArrayList;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.faithnmn.learnenglishbc.R;
import com.faithnmn.learnenglishbc.model.Transcript;

public class LessionAdapter extends ArrayAdapter<Transcript> {
	private ArrayList<Transcript> configurations;
	private LayoutInflater inflater;
	private int currentPlayingIndex = 0;
    public LessionAdapter(Context context,LayoutInflater inflater, int textViewResourceId,
        ArrayList<Transcript> objects) {
      super(context, textViewResourceId, objects);
      this.configurations = objects;
      this.inflater = inflater;
    }
    
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
    	ViewHolder holder;
    	if(convertView == null){
    		convertView = inflater.inflate(R.layout.lession_item_row, null);
    		holder = new ViewHolder();
    		holder.rowScript = (TextView) convertView.findViewById(R.id.row_content);
    		holder.rowID = (LinearLayout)convertView.findViewById(R.id.rowID);
    		convertView.setTag(holder);
    	}else{
    		holder = (ViewHolder) convertView.getTag();
    	}
    	if(position == currentPlayingIndex){
    		holder.rowID.setBackgroundColor(Color.parseColor("#aae037"));
    	}else{
    		holder.rowID.setBackgroundColor(Color.TRANSPARENT);
    	}
    	holder.rowScript.setText(configurations.get(position).content);
    	return convertView;
    }

    public void setCurrentPlayingIndex(int currentIndex){
    	if(currentIndex != currentPlayingIndex){
    		currentPlayingIndex = currentIndex;
//    		notifyDataSetChanged();
    	}
    }
    
    @Override
    public int getCount() {
    	return configurations.size();
    }
    
    @Override
    public boolean hasStableIds() {
      return true;
    }
    
    private class ViewHolder{
    	private TextView rowScript;
    	private LinearLayout rowID;
    }
    
  }